package com.thermal.thermal_inspection.service.impl;

import com.thermal.thermal_inspection.entity.MapDetail;
import com.thermal.thermal_inspection.entity.NfcManage;
import com.thermal.thermal_inspection.mapper.MapDetailMapper;
import com.thermal.thermal_inspection.mapper.NfcMapper;
import com.thermal.thermal_inspection.service.NfcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NfcServiceImpl implements NfcService {
    @Autowired
    private NfcMapper nfcMapper;
    @Autowired
    private MapDetailMapper mapDetailMapper;
    /**
     * 新建NFC信息
     * @param nfcManage
     * @return Integer
     */
    @Override
    public Integer newNFCManage(NfcManage nfcManage) throws Exception{
        return nfcMapper.newNFCManage(nfcManage);
    }

    /**
     * 根据NFC名字查询NFC信息
     * @param nfcName
     * @return NfcManage
     */
    @Override
    public NfcManage getNfcManageByNfcName(String nfcName) {
        return nfcMapper.getNFCManageByNfcName(nfcName);
    }

    /**
     * 根据NFC信息查询NFC信息
     * @param nfcMsg
     * @return NfcManage
     */
    @Override
    public NfcManage getNfcManageByNfcMsg(String nfcMsg) {
        return nfcMapper.getNFCManage(nfcMsg);
    }

    /**
     * 获取所有NFC信息
     * @return List<NfcManage>
     */
    @Override
    public List<NfcManage> getAllNfcManages() {
        NfcManage nfcManage = new NfcManage();
        nfcManage.setNfcMsg("");
        nfcManage.setNfcName("无");
        List<NfcManage> nfcManages = nfcMapper.getAllNFCManages();
        nfcManages.remove(nfcManage);
        return nfcManages;
    }

    /**
     * 修改NFC信息
     * @param nfcManage
     * @return Integer
     */
    @Override
    public Integer updateNfcManage(NfcManage nfcManage) {
        return nfcMapper.updateNFCManage(nfcManage);
    }

    /**
     * 删除NFC信息
     * @param nfcMsg
     * @return Integer
     */
    @Override
    public Integer deleteNfcManage(String nfcMsg) {
        return nfcMapper.deleteNFCManage(nfcMsg);
    }

    /**
     * 判断NFC名字是否重复
     * @param nfcName
     * @return boolean
     */
    @Override
    public boolean isRepeatOfName(String nfcName) {
        List<NfcManage> nfcManages = nfcMapper.getAllNFCManages();
        for (NfcManage nfcManage : nfcManages){
            if (nfcManage.getNfcName().equals(nfcName))
                return true;
        }
        return false;
    }

    /**
     * 判断NFC是否有被使用
     * @param nfcMsg
     * @return String
     */
    @Override
    public String isUseNFC(String nfcMsg) {
        MapDetail mapDetail = mapDetailMapper.getMapDetailByNfcMsg(nfcMsg);
        if (mapDetail != null)
            return "此NFC正在被地图点位使用，无法删除！";
        return null;
    }
}
